var StartMainLayer = cc.Layer.extend({
	lead:null,
	real:null,
	ctor:function (title_str,purpose_str,principle_str) {
		this._super();		
		//加载标题,实验目的,实验原理
		this.loadStr(title_str,purpose_str,principle_str);
		// 加载主页
		this.loadIndex();
		// 加载关于
		this.loadAbout();	
		return true;
	},
	loadStr:function(expId,title_str,purpose_str,principle_str){
		var expId = gg.expId;
		for(var i in expInfo){
			if( expInfo[i].expId == expId){
				var purpose_str=expInfo[i].expPurpose;
				var principle_str=expInfo[i].expPrinciple;
				var title_str=expInfo[i].expTitle;	
				var isDemo = expInfo[i].expDemo;
			}
		}	
		var title = new cc.LabelTTF(title_str,gg.fontName2,gg.fontSize12);
		title.setPosition(791 * 0.5, gg.height - 266 - title.height * 0.5);
		this.addChild(title,2);
		this.purpose_win = new WinFrame(this,1,purpose_str,"#button/purpose.png");
		this.principle_win= new WinFrame(this,1,principle_str,"#button/principle.png");
		
		// 加载菜单按钮
		this.loadButton(isDemo);
	},
	loadButton:function(){
		if(gg.expDemo == TAG_TYPE_TEST){
			//演示模式，测试模式
			this.leadButton = new ButtonScale(this,"#demoButton.png",this.callback);		
			this.realButton = new ButtonScale(this,"#testButton.png",this.callback);		
		}else if(gg.expDemo == TAG_TYPE_NORMAL){
			//引导模式，实战模式
			this.leadButton = new ButtonScale(this,"#leadButton.png",this.callback);		
			this.realButton = new ButtonScale(this,"#realButton.png",this.callback);		
		}
		this.leadButton.setPosition(cc.p(gg.width -125 - this.leadButton.width * 0.5, gg.height - 133 - this.leadButton.height * 0.5));
		this.leadButton.setTag(TAG_LEAD);
		this.leadButton.setLocalZOrder(3);
		gg.buttonEnableArr.push(this.leadButton);
		
		this.realButton.setPosition(cc.p(gg.width -125 -  this.realButton.width * 0.5, gg.height - 275 - this.realButton.height * 0.5));
		this.realButton.setTag(TAG_REAL);
		this.realButton.setLocalZOrder(3);
		gg.buttonEnableArr.push(this.realButton);
		//实验目的
		this.purposeButton = new ButtonScale(this,"#purposeButton.png",this.callback);
		this.purposeButton.setPosition(cc.p(gg.width -125 - this.purposeButton.width * 0.5 , gg.height - 419 - this.purposeButton.height * 0.5));
		this.purposeButton.setTag(TAG_PURPOSE);
		this.purposeButton.setLocalZOrder(3);
		gg.buttonEnableArr.push(this.purposeButton);
		//实验原理
		this.principleButton = new ButtonScale(this,"#principleButton.png",this.callback);
		this.principleButton.setPosition(cc.p(gg.width -125 - this.principleButton.width * 0.5, gg.height - 561 - this.principleButton.height * 0.5));	
		this.principleButton.setTag(TAG_PRINCIPLE);
		this.principleButton.setLocalZOrder(3);
		gg.buttonEnableArr.push(this.principleButton);
//		//游戏
//		this.gameButton = new ButtonScale(this,"#gameButton.png",this.callback);
//		this.gameButton.setPosition(cc.p(238 + this.purposeButton.width + 116 + this.principleButton.width + 116 + this.gameButton.width * 0.5, 125 + this.gameButton.height * 0.5));
//		this.gameButton.setTag(TAG_GAME);
//		this.gameButton.setLocalZOrder(3);
//		gg.buttonEnableArr.push(this.gameButton);
	},
	loadIndex:function(){
		this.indexButton = new ButtonScale(this,"#indexButton.png",this.callback);
		this.indexButton.setPosition(cc.p(20 + this.indexButton.width * 0.5, 30 + this.indexButton.height * 0.5));
		this.indexButton.setTag(TAG_INDEX);
		this.indexButton.setLocalZOrder(5);
		gg.buttonEnableArr.push(this.indexButton);
	},
	loadAbout:function(){
		this.aboutButton = new ButtonScale(this,"#aboutButton.png",this.callback);
		this.aboutButton.setPosition(cc.p(20 + this.aboutButton.width * 0.5, gg.height - 20 - this.aboutButton.height * 0.5));
		this.aboutButton.setTag(TAG_ABOUT);
		this.aboutButton.setLocalZOrder(5);
		gg.buttonEnableArr.push(this.aboutButton);
		
	},
	cWin:function(name){
		if(name == null || name == ""){
			this.win.runAction(cc.fadeOut(0.15));	
			return;
		}
		var seq = cc.sequence(cc.fadeOut(0.15),cc.callFunc(function(){
			this.win.setSpriteFrame(name);
		}, this),cc.fadeIn(0.15));
		this.win.runAction(seq);
	},	
	callback:function(pSend){
		switch(pSend.getTag()){
		case TAG_INDEX:
			ch.howToGo(OP_TYPE_BACK);
			gg.expId=null;
			break;
		case TAG_LEAD:
			cc.log("进入引导模式");
			gg.teach_type = TAG_LEAD;
			gg.runNext(pSend.getTag());
			break;
		case TAG_REAL:
			if(gg.expdemo == TAG_TYPE_TEST){
				cc.log(gg.expId);
				cc.log("进入测试模式");
				gg.runNext(TAG_TEST);
			}else{
				cc.log("进入实战模式");
				gg.teach_type = TAG_REAL;
				gg.runNext(pSend.getTag());
			}
			break;
		case TAG_GAME:
			cc.log("进入小游戏模式");
			gg.runNext(pSend.getTag());
			break;
		case TAG_ABOUT:
			gg.runNext(pSend.getTag());
			break;
		case TAG_PURPOSE:
			cc.log("实验目的");
			if(this.purpose_win.isOpen()){
				gg.synch_l = false;
				this.purpose_win.close();				
			} else {
				gg.synch_l = true;
				this.purpose_win.open();
			}
			break;
		case TAG_PRINCIPLE:
			cc.log("实验原理");
			if(this.principle_win.isOpen()){
				gg.synch_l = false;
				this.principle_win.close();
			} else {				
				gg.synch_l = true;
				this.principle_win.open();
			}
			break;
			default:
				break;
		}
	},
});
